package hzn;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.RequestWrapper;

@RestController
@RequestMapping("/ali")
public class PayCtrl {
    @Autowired
    AlipayClient client;

    @RequestMapping("/pay")
    public String alipay(AlipayBean b){
        //1.设置请求参数
        AlipayTradePagePayRequest req=new AlipayTradePagePayRequest();
        //页面跳转同步通知路径
        //req.setReturnUrl("");
        //下面是服务器异步通知，如果商家不回应，则会重发支付结果
        req.setNotifyUrl("");
        req.setBizContent(JSON.toJSONString(b));
        String result=null;
        try{
            result=client.pageExecute(req).getBody();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }
}
